#include <stdio.h>
#include <termios.h>

#define PASSWORD_LEN 16

int main() {
    struct termios initialsettings;
    struct termios newsettings;
    char password[PASSWORD_LEN] = {0};
    tcgetattr(fileno(stdin), &initialsettings);
    newsettings = initialsettings;
    newsettings.c_lflag &= ~ECHO;
    printf("Please Enter Password:");
    if (tcsetattr(fileno(stdin), TCSAFLUSH, &newsettings) != 0) {
        fprintf(stderr, "Could not set attributes");
    }
    else {
        int i = 0;
        for (i = 0; i < PASSWORD_LEN; ++i) {
            char a = fgetc(stdin);
            if ('\n' == a) {
                break;
            }
            password[i] = a;
        }
        if (i < (PASSWORD_LEN - 1)) {
            password[i + 1] = 0;
        }
        else {
            password[PASSWORD_LEN - 1] = 0;
        }
        tcsetattr(fileno(stdin), TCSANOW, &initialsettings);
        fprintf(stdout, "\nYou entered %s as the password!\n", password);
    }
    return 0;
}